package com.jdk.demo.queue.arrayBlockingQueue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

public class Consumer implements Runnable {

	private  BlockingQueue<String> blockingQueue;

	public Consumer(BlockingQueue<String> blockingQueue) {
		this.blockingQueue = blockingQueue;
	}

	public void run() {
		try {
			while(true) {
				// System.out.println("取出来的元素是：" + blockingQueue.take());
				// System.out.println("取出来的元素是：" + blockingQueue.remove());
				// System.out.println("取出来的元素是：" + blockingQueue.remove("data:1"));
				System.out.println("取出来的元素是：" + blockingQueue.poll(100, TimeUnit.MICROSECONDS));
			}
		} catch (Exception e) {
			System.out.println("消费者在等待新产品的时候被打断了！");
			e.printStackTrace();
		}
	}

}
